﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace dzs.Web.Outstorage
{
    public partial class ShowCheckDetail : Web.Admin.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //待审核出库项目
                if (Session["proid"] != null && Session["login"] != null)
                {
                    DataSet ds = Session["login"] as DataSet;

                    string proid = Session["proid"].ToString();
                    int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());

                    BindGV(proid,user_id,"未审核");
                }
                else if (!string.IsNullOrEmpty(Request["id"]) && Session["login"] != null)//已审核通过出库项目
                {
                    DataSet ds = Session["login"] as DataSet;
                    int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());

                    string proid = Request["id"];

                    BindGV(proid, user_id,"审核通过");
                    this.btn_Yes.Visible = false;
                    this.btn_No.Visible = false;
                }
                else
                {
                    Maticsoft.Common.MessageBox.Show(this, "由于长时间未操作，登录信息已过期，请重新登陆!");
                }
            }
        }
        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.GridView1.PageIndex = e.NewPageIndex;
            if (Session["proid"] != null && Session["login"] != null)
            {
                DataSet ds = Session["login"] as DataSet;

                string proid = Session["proid"].ToString();
                int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());

                BindGV(proid, user_id, "未审核");
            }
            else
            {
                Maticsoft.Common.MessageBox.Show(this, "由于长时间未操作，登录信息已过期，请重新登陆!");
            }
           
        }
        
        //审核通过
        protected void btn_Yes_Click(object sender, EventArgs e)
        {
            List<dzs.Model.out_storageList> li = this.GetCboList();

            dzs.BLL.out_storageList om = new BLL.out_storageList();

            foreach (dzs.Model.out_storageList o in li)
            {
                o.check_status = "审核通过";

                om.Update(o);
            }

            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>window.returnValue=true;parent.close();</script>");

           
        }

        //审核未通过
        protected void btn_No_Click(object sender, EventArgs e)
        {
            List<dzs.Model.out_storageList> li = this.GetCboList();

            dzs.BLL.out_storageList om = new BLL.out_storageList();

            foreach (dzs.Model.out_storageList o in li)
            {
                o.check_status = "审核未通过";

                om.Update(o);
            }

            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>window.returnValue=true;parent.close();</script>");

        }

        private List<dzs.Model.out_storageList> GetCboList()
        {
            List<dzs.Model.out_storageList> li = new List<Model.out_storageList>();

            dzs.BLL.out_storageList om = new BLL.out_storageList();

            for (int i = 0; i < this.GridView1.Rows.Count; i++)
            {
                CheckBox cbo = this.GridView1.Rows[i].FindControl("cbo_check") as CheckBox;

                if (cbo != null && cbo.Checked)
                {

                    Label lbl_out_storageList_id = this.GridView1.Rows[i].FindControl("lbl_out_storageList_id") as Label;//物料ID

                    int oid = 0;
                    if (!string.IsNullOrEmpty(lbl_out_storageList_id.Text))
                    {
                        oid = Convert.ToInt32(lbl_out_storageList_id.Text);
                    }

                    dzs.Model.out_storageList o = om.GetModel(oid);

                    li.Add(o);
                }
            }

            return li;
        }


        private void BindGV(string proid, int check_user_id,string check_status)
        {
            DataSet ds = new dzs.BLL.out_storageList().GetCheckUserDetail
                (" proid='" + proid + "' and check_user_id=" + check_user_id + " and check_status='" + check_status + "'");

            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();
        }
    }
}